/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ChordSelectorPanel.java
 *
 * Created on 30/08/2009, 1:33:12 AM
 */

package net.animats.music.app;

import net.animats.music.*;
import javax.swing.*;
import java.util.*;

/**
 *
 * @author stuart
 */
public class ChordSelectorPanel extends javax.swing.JPanel {

    private List<ChordSelectorListener> listeners = new ArrayList<ChordSelectorListener>();

    public void addListener(ChordSelectorListener _listener) {
        listeners.add(_listener);
    }

    private void callListeners() {
        for (ChordSelectorListener currentListener : listeners) {
            currentListener.chordSelected((String) rootNoteSelector.getSelectedItem(), (String) chordTypeSelector.getSelectedItem());
        }
    }
    /** Creates new form ChordSelectorPanel */
    public ChordSelectorPanel(String _buttonText) {
        initComponents();
        addButton.setText(_buttonText);
    }

    public ChordSelectorPanel() {
        initComponents();
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        addButton = new javax.swing.JButton();
        rootNoteSelector = new javax.swing.JComboBox();
        chordTypeSelector = new javax.swing.JComboBox();

        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        setPreferredSize(new java.awt.Dimension(300, 55));

        addButton.setText("OK");
        addButton.setToolTipText("Add currently selected chord to song.");
        addButton.setMinimumSize(new java.awt.Dimension(107, 25));
        addButton.setPreferredSize(new java.awt.Dimension(79, 25));
        addButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addButtonMouseClicked(evt);
            }
        });

        rootNoteSelector.setModel(new DefaultComboBoxModel(Note.getNoteNamesArray()));
        rootNoteSelector.setToolTipText("Select the root note for the chord you wish to add.");
        rootNoteSelector.setMinimumSize(new java.awt.Dimension(69, 25));
        rootNoteSelector.setPreferredSize(new java.awt.Dimension(69, 25));

        chordTypeSelector.setModel(new DefaultComboBoxModel(ChordType.getChordTypeNamesArray()));
        chordTypeSelector.setToolTipText("Select the type of chord you wish to add.");
        chordTypeSelector.setMinimumSize(new java.awt.Dimension(107, 25));
        chordTypeSelector.setPreferredSize(new java.awt.Dimension(107, 25));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rootNoteSelector, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chordTypeSelector, 0, 106, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rootNoteSelector, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chordTypeSelector, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(addButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void addButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addButtonMouseClicked
        callListeners();
    }//GEN-LAST:event_addButtonMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addButton;
    private javax.swing.JComboBox chordTypeSelector;
    private javax.swing.JComboBox rootNoteSelector;
    // End of variables declaration//GEN-END:variables

}
